package com.xfp.controller;

import com.xfp.pojo.dto.PageDto;
import com.xfp.pojo.dto.PolicyDto;
import com.xfp.pojo.dto.PolicyQueryDto;
import com.xfp.pojo.vo.PolicyQueryVo;
import com.xfp.pojo.vo.PolicyVmQueryVo;
import com.xfp.pojo.vo.VmPolicyVo;
import com.xfp.service.PolicyService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/api/vm-service")
public class PolicyController {

    @Autowired
    private PolicyService policyService;

    /**
     * 策略搜索
     */
    @GetMapping("/policy/search")
    @ApiOperation("策略搜索")
    public PolicyQueryVo policyPage(PolicyQueryDto dto){
        log.info("策略搜索：{}",dto);
        PolicyQueryVo vo = policyService.policyPage(dto);
        return vo;
    }

    /**
     * 新增策略
     */
    @PostMapping("/policy")
    @ApiOperation("新增策略")
    public Boolean insertPolicy(@RequestBody PolicyDto dto){
        log.info("新增策略");
        policyService.insertPolicy(dto);
        return true;
    }

    /**
     * 修改策略
     */
    @PutMapping("/policy/{policyId}")
    @ApiOperation("修改策略")
    public Boolean updatePolicy(@PathVariable Integer policyId,@RequestBody PolicyDto dto){
        log.info("修改策略，{}，{}",policyId,dto);
        policyService.updatePolicy(policyId,dto);
        return true;
    }

    /**
     * 删除策略
     */
    @DeleteMapping("/policy/{policyId}")
    @ApiOperation("删除策略")
    public Boolean deletePolicy(@PathVariable Integer policyId){
        log.info("删除策略：{}",policyId);
        policyService.deletePolicy(policyId);
        return true;
    }

    /**
     *根据策略搜索售货机
     */
    @GetMapping("/policy/vmList/{policyId}")
    @ApiOperation("根据策略搜索售货机")
    public PolicyVmQueryVo PolicyVmQuery(@PathVariable Integer policyId, PageDto dto){
        log.info("根据策略搜索售货机:{}",policyId);
        PolicyVmQueryVo vo = policyService.PolicyVmQuery(policyId,dto);
        return vo;
    }

    /**
     * 查询售货机策略
     */
    @GetMapping("/policy/vmPolicy/{innerCode}")
    @ApiOperation("查询售货机策略")
    public VmPolicyVo findVmPolicy(@PathVariable String innerCode ){
        log.info("查询售货机策略：{}",innerCode);
        VmPolicyVo vo = policyService.findVmPolicy(innerCode);
        return vo;
    }

}
